package com.sskj.xgja.transaction;

import com.sskj.base.utils.RxUtils;
import com.sskj.xgja.BasePresenter;
import com.sskj.xgja.api.Api;
import com.sskj.xgja.api.ApiObserver;
import com.sskj.xgja.transaction.data.HoldOrderBean;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/03/20
 */
class HoldPositionPresenter extends BasePresenter<HoldPositionFragment> {

    public void getHoldList(String account, boolean showLoading) {
        Api.getInstance().getHoldList()
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<List<HoldOrderBean>>(this, showLoading) {
                    @Override
                    public void onSuccess(List<HoldOrderBean> data) {
                        mView.setData(data);
                    }

                    @Override
                    public void onError(Throwable e) {
//                        super.onError(e);
                        if (mView != null) {
                            if (showLoading) {
                                mView.hideLoading();
                            }
                        }
                        mView.finishRefresh();
                        mView.setData(null);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.finishRefresh();
                    }
                });
    }


    public void closeOrder(String orderId) {
        Api.getInstance().closeOrder(orderId)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<Object>(this, true) {
                    @Override
                    public void onSuccess(Object data) {
                        mView.closeOrderSuccess();
                    }
                });

    }

    // 止盈止损
    public void getCoinDetail(String account, HoldOrderBean item) {
//        Api.getInstance().getCoinDetail("oneStockInfo", account, item.getStockCode())
//                .compose(RxUtils.transform())
//                .subscribe(new ApiObserver<List<CoinDetail>>(this, true) {
//                    @Override
//                    public void onSuccess(List<CoinDetail> data) {
//                        mView.setCoinDetail(data, item);
//                    }
//
//                });
    }


    // 设置止盈止损
    public void setProfit(String account, String id, String win, String loss) {
//        Api.getInstance().setProfit("stockCountManage", account, id, loss, win)
//                .compose(RxUtils.transform())
//                .subscribe(new ApiObserver<String>(this, true) {
//                    @Override
//                    public void onSuccess(String data) {
//                        mView.setProfitSuccess();
//                    }
//                });

    }
}
